package api

import (
	auto "beergo/app/com/auto/controller"
	"beergo/app/com/conf"
	"beergo/conf/const/code"
	"github.com/beego/beego/v2/server/web"
)

type BannerAdminController struct {
	auto.BannerController
}

func init() {
	web.Router(conf.UrlPrefix+"/Banner/:id", &BannerAdminController{}, "*:GetAction")
	web.Router(conf.UrlPrefix+"/Banner/info", &BannerAdminController{}, "*:InfoAction")
	web.Router(conf.UrlPrefix+"/Banner/scan", &BannerAdminController{}, "*:ScanAction")
	web.Router(conf.UrlPrefix+"/Banner/list", &BannerAdminController{}, "*:ListAction")
	web.Router(conf.UrlPrefix+"/Banner/update", &BannerAdminController{}, "*:UpdateAction")
	web.Router(conf.UrlPrefix+"/Banner/create", &BannerAdminController{}, "*:CreateAction")
	web.Router(conf.UrlPrefix+"/Banner/copy", &BannerAdminController{}, "*:CopyAction")
	web.Router(conf.UrlPrefix+"/Banner/edit", &BannerAdminController{}, "*:EditAction")
	web.Router(conf.UrlPrefix+"/Banner/delete", &BannerAdminController{}, "*:DeleteAction")
	web.Router(conf.UrlPrefix+"/Banner/:id/:field", &BannerAdminController{}, "*:SonsAction")
	web.Router(conf.UrlPrefix+"/Banner/choice", &BannerAdminController{}, "*:ChoiceAction")
	web.Router(conf.UrlPrefix+"/Banner/category", &BannerAdminController{}, "*:CategoryAction")
}

// func (this *BannerAdminController) Prepare() {}
func (this *BannerAdminController) ListAction() {
	if this.QueryBuilder.Conditions == nil {
		this.QueryBuilder.Conditions = make(map[string]interface{})
		this.QueryBuilder.Conditions["position"] = 1
	}
	//_, ok := this.QueryBuilder.Conditions["position"]
	//if !ok {
	//
	//}

	lists, err := this.Repository.GetList(this.QueryBuilder)
	if err != nil {
		this.StopError(code.Error, "系统错误", err.Error())
	}
	if this.QueryBuilder.IsTree {
		var re = make([]interface{}, 0)
		for _, list := range lists {
			list.SetQueryBuilder(this.QueryBuilder)
			re = append(re, list.Scan(this.QueryBuilder.MakeScans(), this.QueryBuilder.GetDepth(), ""))
		}
		this.JsonData["lists"] = re
		this.JsonData["query"] = this.QueryBuilder.FeedBack()
		this.ReturnSuccess("OK", this.JsonData)
	} else {
		this.JsonData["lists"] = lists
		this.JsonData["query"] = this.QueryBuilder.FeedBack()
		this.ReturnSuccess("OK", this.JsonData)
	}
}

//func (this *BannerAdminController) GetAction() {}
//func (this *BannerAdminController) InfoAction() {}
//func (this *BannerAdminController) ScanAction() {}
//func (this *BannerAdminController) CreateAction() {}
//func (this *BannerAdminController) UpdateAction() {}
//func (this *BannerAdminController) CopyAction() {}
//func (this *BannerAdminController) DeleteAction() {}
//func (this *BannerAdminController) EditAction() {}
//func (this *BannerAdminController) SonsAction() {}
//func (this *BannerAdminController) ChoiceAction() {}
//func (this *BannerAdminController) CategoryAction() {}
